import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from views.tabs.local_upgrade_tab import LocalUpgradeTab
from views.tabs.network_connection_tab import NetworkConnectTab
from views.tabs.wifi_connection_tab import WiFiConnectionTab
from views.tabs.network_monitor_tab import NetworkMonitorTab
from views.tabs.inosuke_upgrade_tab import InosukeLocalUpgradeTab
from ttkbootstrap import Style


class MainView:
    def __init__(self, controller):
        self.controller = controller
        self.root = ttk.Window()
        self.style = Style()
        self.create_widgets()
        self.create_notebook()
        self.add_tabs()
        self.root.mainloop()

    def create_widgets(self):
        # 窗口标题
        self.root.title("B3FT")
        # 禁止改变窗口大小
        self.root.resizable(False, False)
        # 窗口大小
        width = 900
        height = 600
        # 根据屏幕分辨率计算窗口位置
        position_x = self.root.winfo_screenwidth() // 2 - width // 2
        position_y = self.root.winfo_screenheight() // 2 - height // 2
        # 设置窗口大小和位置
        self.root.geometry(f"{width}x{height}+{position_x}+{position_y}")
        # 窗口图标
        self.root.iconbitmap("")

    def create_notebook(self):
        # 创建一个notebook标签
        self.notebook = ttk.Notebook(self.root, style="info")

        self.style.configure("TNotebook.Tab", width=25, font=("微软雅黑", 12), anchor=CENTER)
        self.notebook.pack(fill=BOTH, expand=True)

    def add_tabs(self):
        InosukeLocalUpgradeTab(ttk, self.style, self.notebook, "Inosuke升级")
        LocalUpgradeTab(ttk, self.style, self.notebook, "本地升级")
        NetworkConnectTab(ttk, self.style, self.notebook, "网络连接")
        NetworkMonitorTab(ttk, self.style, self.notebook, "网络监控")
        WiFiConnectionTab(ttk, self.style, self.notebook, "WiFi连接")
